package com.ccp.dev.system.service;
import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.util.UUIDUtils;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.system.dao.MessageReplyDao;
import com.ccp.dev.system.model.MessageReply;
import com.ccp.dev.system.model.SysUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
 * 消息回复 Service类
 * @author :pkq
 * @Date:2012-01-14 15:15:43
 */
@Service
public class MessageReplyService extends BaseService<MessageReply>
{
	@Resource
	private MessageReplyDao dao;
	public MessageReplyService()
	{
	}

	/**
	 * 保存 MessageReply
	 * @param messageReply
	 * @param sysUser
	 */
	@Transactional(rollbackFor = Exception.class)
	public void saveReply(MessageReply messageReply, SysUser sysUser) throws Exception{
		messageReply.setId(UUIDUtils.getUUIDFor32());
		messageReply.setReplyId(sysUser.getUserId());
		messageReply.setReply(sysUser.getFullName());
		Date now = new Date();
		messageReply.setReplyTime(now);
		add(messageReply);
	}

	/**
	 *
	 * 获取消息回复者
	 * @param queryFilter
	 * @return List<MessageReply>
	 */
	public List<MessageReply> getAll(QueryFilter queryFilter) {
		return 	dao.getAll(queryFilter);
	}

	/**
	 * 发送人获取消息回复者
	 * @param queryFilter
	 * @return
	 */
	public List<MessageReply> getAllByUserName(QueryFilter queryFilter) {
		return 	dao.getAllByUserName(queryFilter);
	}

	/**
	 *
	 * 根据id获取消息回复者
	 * @param id
	 * @return MessageReply
	 */
	public MessageReply getById(String id) {
		 return  dao.getById(id);
	}

	/**
	 *
	 * 根据消息id获取消息回复者
	 * @param messageId
	 * @return List<MessageReply>
	 */
	public List<MessageReply> getByMessageId(String messageId) {
		return dao.getReplyByMsgId(messageId);
	}
}
